<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>广播信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../jquery-easyui-1.5.3/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../jquery-easyui-1.5.3/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../js/jquery.qrcode.min.js"></script>
    <script src="../layui/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item" style="margin-top: 10px">
        <label class="layui-form-label">广播内容：</label>
        <div class="layui-input-block" style="width: 300px">
            <input type="text" name="content" id="content" lay-verify="required" placeholder="请输入广播内容"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
        </div>
    </div>
</form>
</body>
<script>
    layui.use(['form', 'layer'], function () {
        var form = layui.form
            , layer = layui.layer
            , $ = layui.jquery

        $.ajax({
            type: "get",
            dataType: "json",
            url: "/refuse-web/api/notice/info",
            async: true,
            success: function (data) {
                var res = data.data;
                if (res != undefined && res != null && res != "") {
                    $("#content").val(res.content);
                } else {
                    layer.msg("无数据", {icon: 5, time: 1000});
                }
            },
            error: function (msg) {
                alert("服务器请求失败！", {icon: 5});
            }
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            var content = $("#content").val();
            alert(content);
            $.ajax({
                url: '/refuse-web/api/notice/update',
                method: 'post',
                data: {content:content},
                //contentType: 'application/json; charset=UTF-8',//设置content-type
                //data: JSON.stringify(image),//将对象转换成json字符串
                dataType: 'JSON',
                success:
                    function (res) {
                        if (res.code = '0') {
                            layer.msg('修改成功', {icon: 1, time: 1000}, function () {
                                location.reload();
                            });
                        } else {
                            layer.msg("修改失败", {icon: 5, time: 1000}, function () {
                                location.reload();
                            });
                        }
                    }
                ,
                error: function (data) {
                    layer.msg("服务器忙...", {icon: 5})
                }
            });
            return false;
        })
    });
</script>
</html>